<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/plugins/datagrid-detailview.js"></script>
<script type="text/javascript">
 $(function(){

	 $('#cuslog').datagrid({
		 pageList:[10]
	 	});
	 
	$('#customerslogadd').bind('click',function(){
		var row = $('#cuslog').datagrid('getSelected');
			if (row) {
				$('#dlgcustlog').dialog('open');
				$('#cus_id').val(row.cus_id);
			}else {
				 $.messager.show({
					 title: '提示',
					 msg: "请选择一条数据"
					 });
			 }
		});
	$("#saveCustomersLog").bind('click',function(){
		$('#fmcustlog').form('submit',{
							onSubmit:function(){
								var content = $('#logcontent').val().trim();
								if(content == '') {	
									 $.messager.show({
										 title: 'Error',
										 msg: "内容必须填写"
										 });
									 return false;
								} else {
									return true;
								}
							},
							 success: function(result){
								 var result = eval('('+result+')');
								 if (result.errorMsg){
									 $.messager.show({
									 title: 'Error',
									 msg: result.errorMsg
									 });
								 } else {
									 $.messager.show({
										 title: '成功',
										 msg: "追踪添加成功"
										 });
									 $('#dlgcustlog').dialog('close'); // close the dialog
									 //$('#cuslog').datagrid('reload'); // reload the user data
								 }
							 	}
							});
	});

	$('#cuslog').datagrid({
		 view: detailview,
		 detailFormatter:function(index,row){
		 return '<div style="padding:2px"><table class="ddv"></table></div>';
		 },
		 onExpandRow: function(index,row){
		 var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
		 ddv.datagrid({
			 url:'${pageContext.request.contextPath}/customersLog/getCustomerLogJson.html?cus_id='+row.cus_id,
		 	fitColumns:true,
		 	singleSelect:true,
		 	loadMsg:'正在加载...',
		 	height:'auto',
		 	columns:[[
				 {field:'e_sn',title:'工号',width:100},
				 {field:'e_name',title:'发布者',width:100},
				 {field:'content',title:'内容',width:100},
				 {field:'createTime',title:'时间',width:100}
			 ]],
			 onResize:function(){
				   $('#cuslog').datagrid('fixDetailRowHeight',index);
				  },
			  onLoadSuccess:function(){
				  setTimeout(function(){
				  $('#cuslog').datagrid('fixDetailRowHeight',index);
				  },0);
				  }
			 });
		   }
		 });
	  $('#cuslog').datagrid('load',{  
		   cus_name: ""
	    });  
	
	 $("#search").click(function(){
		   $('#cuslog').datagrid('load',{  
			   cus_name: $('#cus_name').val()
		    });  
		});
 }) 
  
</script>
</head>

<body>
 	<div class="easyui-tabs" style="width:auto;height:auto">
		<div title="客户列表" style="padding:10px">
		     <table id="cuslog" class="easyui-datagrid" style="width:auto;height:600px"
					url="${pageContext.request.contextPath}/custome/viewCustomersJson/pri.html"
					singleSelect="true"
					pagination="true"
					pagePosition="both"
					fitColumns="true"
					toolbar="#toolbarcustlog"
					>
			    <thead>
				    <tr>
				    <th data-options="field:'cus_name',width:100">姓名</th>
				    <th data-options="field:'cus_status',width:100">状态</th>
				    <th data-options="field:'cus_type',width:100">类型</th>
				   	<th data-options="field:'days',width:100">成为公共客户期限</th>
				   	<th data-options="field:'createTime',width:300">创建时间</th>
				    </tr>
			    </thead>
		    </table>
	    </div>
    </div>
   
     <div id="toolbarcustlog">
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="customerslogadd">客户追踪</a>
		<div style="padding-left:10px;">	
			 <span>姓名</span>  
   			 <input id="cus_name" style="line-height:26px;border:1px solid #ccc">  
    		 <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" id="search" >Search</a>  
		</div>	
	</div>
	
	<div id="dlgcustlog" class="easyui-dialog" style="width:300px;height:300px;padding:10px 20px"
		closed="true" buttons="#dlg-buttonlog" title="客户追踪" model="true">
		 <div class="ftitle">添加追踪信息</div>
		<form id="fmcustlog" method="post" novalidate action="${pageContext.request.contextPath}/customersLog/saveCustomersLog.html">
			<input type="hidden" id="cus_id" name="cus_id"/>
			<div class="fitem">
				<label>内容:</label>
				<textarea name="logcontent" id="logcontent" rows="5" cols="25" ></textarea>
			</div>
		</form>
	</div>
	
 <div id="dlg-buttonlog">
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" id="saveCustomersLog">保存</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgcustlog').dialog('close')">取消</a>
</div>
